package com.antu.first.web.merchant;

import com.antu.first.bean.Hotel;
import com.antu.first.bean.Merchant;
import com.antu.first.bean.Room;
import com.antu.first.bean.RoomType;
import com.antu.first.service.RoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2018/3/4.  /roomController/updateRoomInfoByHoteId
 */
@Controller
@RequestMapping("/roomController")
public class RoomController {
    @Autowired
    RoomService roomService;
    Map<String,Object> map;
    List<Room>list=new ArrayList();
    boolean flag;

    /**
     *
     * @param room
     * @param currentPage 当前页码
     * @param pageSize 每页条数
     * @return
     */
    @RequestMapping(value = "/selectRoomsByHotelIdAndRoonTypeId")
    @ResponseBody
    public Map<String,Object> selectRoomsByHotelIdAndRoonTypeId(Room room, Integer currentPage, Integer pageSize, HttpServletRequest httpServletRequest){
        Merchant merchant= (Merchant) httpServletRequest.getSession().getAttribute("merchant");//取出对象
        room.setHotel( merchant.getHotel());
        return  roomService.selectRoomsByHotelIdAndRoomTypeId(room,currentPage,pageSize);
    }

    /**
     *更新房间信息
     * @param room 前台传入的数据
     * @return msg
     */
    @RequestMapping(value = "/updateRoomInfoByHoteId")
    @ResponseBody
    public Map<String,Object> updateRoomInfoByHoteId(Room room,HttpServletRequest httpServletRequest){
        Merchant merchant= (Merchant) httpServletRequest.getSession().getAttribute("merchant");//取出对象
        room.setHotel( merchant.getHotel());
        return roomService.updateRoomInfoByHoteId(room);
    }

    /**
     * 按照酒店ID和房间类型ID新增房间
     * @param room
     * @return
     */
    @RequestMapping(value = "/addRoomByHotelId")
    @ResponseBody
    public Map<String,Object> addRoomByHotelId(Room room,HttpServletRequest httpServletRequest){
        Merchant merchant= (Merchant) httpServletRequest.getSession().getAttribute("merchant");//取出对象
        room.setHotel( merchant.getHotel());
        return roomService.addRoomByHotelId(room);
    }

    /**
     * 按照主键去删除一个房间
     * @param room
     * @return
     */
    @RequestMapping(value = "/deleteRoomByIdHotelId")
    @ResponseBody
    public Map<String,Object>deleteRoomByIdHotelId(Room room,HttpServletRequest httpServletRequest){
        Merchant merchant= (Merchant) httpServletRequest.getSession().getAttribute("merchant");//取出对象
        room.setHotel( merchant.getHotel());
        return roomService.deleteRoomByIdHotelId(room);
    }
}
